﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using OneOfAll.Common.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OneOfAll.ViewModel
{
    public class PeopleInfoViewModel : ViewModelBase
    {
        #region 字段

        #endregion

        #region 属性
        private PeopleModel peopleInfo = null;
        public PeopleModel PeopleInfo
        {
            get { return peopleInfo; }
            set { peopleInfo = value; RaisePropertyChanged(); }
        }
        #endregion

        #region 命令
        private RelayCommand<string> buttonClickCmd;
        public RelayCommand<string> ButtonClickCmd
        {
            get
            {
                if (buttonClickCmd == null)
                {
                    buttonClickCmd = new RelayCommand<string>((p) => ButtonClickFunc(p));
                }
                return buttonClickCmd;
            }
        }


        #endregion

        #region 方法
        private void ButtonClickFunc(string p)
        {
            switch (p)
            {
                case "返回":
                    Messenger.Default.Send("PeopleInfoView", Global.GlobalResource.CloseChildrenWindow);
                    break;
            }
        }

        private void ShowPeopleInfo(PeopleModel info)
        {
            PeopleInfo = info;
        }

        private void RegisterMessages()
        {
            Messenger.Default.Register<PeopleModel>(this, Global.GlobalResource.ShowPeopleInfo, new Action<PeopleModel>(info =>
            {
                ShowPeopleInfo(info);
            }));
        }


        #endregion

        public PeopleInfoViewModel() 
        {
            RegisterMessages();
        }


    }
}
